package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.CustomerBean;
import com.project.service.ICustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("customer")
@RestController
public class CustomerController {
    @Autowired
    private ICustomerService customerService;

    @RequestMapping("findByItem")
    private IPage<CustomerBean> findByItem(Integer pageNO, String customerName, String scope){
        return customerService.findByItem(pageNO, customerName, scope);
    }

    @RequestMapping("findById")
    public  CustomerBean findById(Integer id){
        return  customerService.findById(id);
    }

    @RequestMapping("updateBySupplierId")
    public String updateBySupplierId(Integer customerId,String newHeadName,String newHeadPhone,String scope){
        customerService.updateBySupplierId(customerId, newHeadName, newHeadPhone, scope);
        return "success";
    }

    @RequestMapping("addCustomer")
    public String addCustomer(CustomerBean customerBean){
        if (customerBean.getCustomerName().equals("undefined")){
            return "error";
        }
        if (customerBean.getHeadName().equals("undefined")){
            return "error";
        }
        if (customerBean.getHeadPhone().equals("undefined")){
            return "error";
        }
        if (customerBean.getAddress().equals("undefined")){
            return "error";
        }
        if (customerBean.getEmail().equals("undefined")){
            return "error";
        }
        if (customerBean.getScope().equals("undefined")){
            return "error";
        }
        customerService.addCustomer(customerBean);
        return "success";
    }

}
